<?php
/**
 * Hoffman Framework
 *
 * LICENSE
 *
 * This source file is subject to the GNU LGPL 2.1 license that is bundled
 * with this package in the file license.txt.
 * It is also available through the world-wide-web at this URL:
 * http://creativecommons.org/licenses/LGPL/2.1
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to annop@thaicyberpoint.com so we can send you a copy immediately.
 *
 * @package    Hoffman
 * @author     Ford AntiTrust
 * @copyright  Copyright (c) 2008 Ford AntiTrust (http://www.thaicyberpoint.com/ford/blog)
 * @since      Version Rv 0.2
 * @license    http://creativecommons.org/licenses/LGPL/2.1
 *             GNU LGPL 2.1
 * @filesource
 */

/**
 * @see Zend_Registry
 */
require_once 'Zend/Registry.php';

/**
 * @see Zend_Session
 */
require_once 'Zend/Session.php';

/**
 * @see Hmf_Authen
 */
require_once 'Hmf/Authen.php';

/**
 * Authen
 *
 * @package     Hoffman
 * @subpackage  Hmf
 * @category    Authen
 * @author      Ford AntiTrust
 * @version     SVN: $Id: Session.php 167 2010-02-18 10:32:16Z annop.s@gmail.com $
 * @link        http://www.thaicyberpoint.com/ford/blog/hmf
 */

class Hmf_Authen_Storage_Session extends Hmf_Authen {

    /**
     * Store Zend_Session_Namespace instance
     *
     * @var Zend_Session_Namespace
     */
    private $session;

    /**
     * Load session data with 'session.authen.namespace' index from app_config to Zend_Session_Namespace instance
     */
    public function __construct() {

        $app_config = Zend_Registry::get('app_config');

        $this->session = new Zend_Session_Namespace($app_config['session.authen.namespace']);

    }

    /**
     * Get addition information authen
     *
     * @return mixed
     */
    public function getInfo() {

        return empty($this->session->info) ? null : $this->session->info;
    }

    /**
     * Get Role string
     *
     * @return string
     */
    public function getRole() {

        return empty($this->session->role) ? 'Guest' : $this->session->role;
    }

    /**
     * Set addition information authen
     *
     * @param mixed $data
     */
    public function setInfo($data) {

        $this->session->info = $data;
    }

    /**
     * Set role string
     *
     * @param string $role
     */
    public function setRole($role) {

        $this->session->role = $role;
    }

    /**
     * Check $role match to role string
     *
     * @param string $role
     */
    public function isRole($role) {

        return ($this->getRole() == $role) ? true : false;
    }

    /**
     * Clear addition information authen and role string
     *
     */
    public function clear() {

        return $this->session->unsetAll();
    }

}
?>